/*--------------------------------------------------------------------------------------------------
Yatak Operation System Project Copyright 2012-2013
Author : Ilya Churaev
Started : 20 Apr 2012		Updated : 29 Jun 2012
File Name : isr.h			Purpose : install ISR
--------------------------------------------------------------------------------------------------*/
#ifndef _ISR_H
#define _ISR_H

#ifdef __cplusplus
extern "C" {
#endif

#include <yatak/regs.h>
#include <types.h>

/*The x86 architecture is an interrupt driven system. External events trigger an interrupt - the normal control flow is interrupted and a Interrupt Service Routine (ISR) is called.
Such events can be triggered by hardware or software. An example of a hardware interrupt is the keyboard: Every time you press a key, the keyboard triggers IRQ1 (Interrupt Request 1), and the corresponding interrupt handler is called. Timers, and disk request completion are other possible sources of hardware interrupts.
Software driven interrupts are triggered by the int opcode; e.g. the services provided by MS-DOS are called by the software triggering INT 21h and passing the applicable parameters in CPU registers.
For the system to know which interrupt service routine to call when a certain interrupt occurs, offsets to the ISR's are stored in the Interrupt Descriptor Table when you're in Protected mode, or in the Interrupt Vector Table when you're in Real Mode.
An ISR is called directly by the CPU, and the protocol for calling an ISR differs from calling e.g. a C function. Most importantly, an ISR has to end with the iret opcode, whereas usual C functions end with ret or retf. The obvious but nevertheless wrong solution leads to one of the most "popular" triple-fault errors among OS programmers. */

#define IRQ0  32
#define IRQ1  33
#define IRQ2  34
#define IRQ3  35
#define IRQ4  36
#define IRQ5  37
#define IRQ6  38
#define IRQ7  39
#define IRQ8  40
#define IRQ9  41
#define IRQ10 42
#define IRQ11 43
#define IRQ12 44
#define IRQ13 45
#define IRQ14 46
#define IRQ15 47

// Разрешает регистрировать обратные вызовы (callbacks) для прерываний или IRQ.
// Чтобы избежать неразберихи используйте для IRQ в качестве первого параметра 
// определения #define, укаазанные выше.
// some typdefs for calling isr handlers
typedef void (*isr_t)(registers_t*);
// typedef void (*irq_t)(struct registers);
void register_interrupt_handler(uint8 n, isr_t handler);

// the prototypes called by the common_stubs
void isr_handler(registers_t regs);
void irq_handler(registers_t regs);

#ifdef __cplusplus
}
#endif

#endif
